package com.longjianghuasheng.logistics.business.mine.fragment

import android.os.Bundle
import android.view.View
import coil.load
import com.longjianghuasheng.logistics.R
import com.longjianghuasheng.logistics.base.BaseMultiStateFragment
import com.longjianghuasheng.logistics.business.mine.viewmodel.PersonalInformationViewModel
import com.longjianghuasheng.logistics.databinding.FragmentPersonalInformationBinding
import com.longjianghuasheng.logistics.ext.observer
import com.longjianghuasheng.logistics.ext.onClickIsLogin
import com.longjianghuasheng.logistics.ext.selectPicture
import com.longjianghuasheng.logistics.ext.showPicker
import java.lang.Deprecated

@Deprecated
class PersonalInformationFragment :
    BaseMultiStateFragment<PersonalInformationViewModel, FragmentPersonalInformationBinding>() {


    private val cardFrontListener = { _: View ->
        selectPicture {

            mViewModel.card_front = it.realPath

            mDatabind.run {
                ivCardFront.load(it.path)
            }


        }

    }
    private val cardBackListener = { _: View ->
        selectPicture {

            mViewModel.card_back = it.realPath

            mDatabind.run {
                ivCardBack.load(it.path)

            }


        }

    }

    override fun layoutId(): Int = R.layout.fragment_personal_information

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        mDatabind.run {

            ivCardFront.setOnClickListener(cardFrontListener)
            ivClickLeft.setOnClickListener(cardFrontListener)
            tvDriverLicensePositive.setOnClickListener(cardFrontListener)

            ivCardBack.setOnClickListener(cardBackListener)
            ivClickRight.setOnClickListener(cardBackListener)
            tvDriverLicenseBack.setOnClickListener(cardBackListener)




            stvSex.setOnClickListener {

                showPicker(options = arrayOf("男", "女")) {

                    mViewModel.sex = if (it == "男") 1 else 2

                    stvSex.setCenterString(it)
                }

            }

            btnCommit.onClickIsLogin {

                mViewModel.run {
                    real_name = stvName.centerEditValue
                    tel = stvPhone.centerEditValue
                    card_no = stvIdentityCard.centerEditValue


                    person_info()
                }

            }


        }
    }

    override fun createObserver() {
        super.createObserver()
        mViewModel.notify.observer(this) {
            navigateUp()
        }
    }

    override fun initData() {
        super.initData()
    }

    override fun lazyLoadData() {
        super.lazyLoadData()
    }

}